$(function() {
	//进入页面加载数据
	if(localStorage.getItem('search_data')) {
		
		var name = localStorage.getItem('search_data');
		console.log(name);
		$.ajax({
			type: 'post',
			url: "http://a.91jfk.com/Product/Shopindex/search_result_data",
			data: {
				name: name
			},
			dataType: 'json',
			success: function(res) {
				console.log(res);

				if(res.code == "1") {
					var msg = res.message;
					for(var i = 0; i < msg.length; i++) {
						pageShow(msg[i].id, msg[i].pname, msg[i].introduce,msg[i].show_pic,msg[i].low_price,msg[i].goods_type);
						
					}
					
				} else {

				}
			},
			error: function(err) {}
		});
	}

	if(localStorage.getItem('hot_data')) {
		
		var text = localStorage.getItem('hot_data');
		console.log(text);
		$.ajax({
			type: 'post',
			url: "http://a.91jfk.com/Product/Shopindex/search_result_data",
			data: {
				name: text
			},
			dataType: 'json',
			success: function(res) {
				console.log(res);
				if(res.code == "1") {
					var msg = res.message;
					for(var i = 0; i < msg.length; i++) {
						pageShow(msg[i].id, msg[i].pname, msg[i].introduce,msg[i].show_pic,msg[i].low_price,msg[i].goods_type);
					
					}
					
				} else {

				}
			},
			error: function(err) {}
		});
	}
	//展示数据的方法
	function pageShow(id, title, introduce,src,price,type) {
		var listBox = $(".good_listBox");
		var listRow = $('<div class="list_row"></div>');
		var goods_type = $('<div type="hidden" class="type">' + type +'</div>');
		var Input = $('<input type="hidden" value="' + id + '">');
		var listLt = $('<div class="list_left"><img src="' + src + '" alt=""></div>');
		var listRt = $('<div class="list_right"><p class="goodLisr_title">' + title + '</p><p class="goodLisr_att">' + introduce + '</p><p 	class="goodLisr_price"><span class="now">¥'+ price +'</span></p><p class="fast_buy">立即购买</p></div>');
		listRow.append(Input).append(listLt).append(listRt).append(goods_type);
		listBox.append(listRow);
	}
	// 点击列表项跳转详情界面
	$(document).on("click", ".list_row", function() {
		console.log("跳转");
		var id = $(this).find("input[type=hidden]").val();
		var type = $(this).find(".type").text();
		console.log(type);
		console.log(id);
		if(type == 1){
			window.location.href = "../Pointshop/point_shop_goodDetail.html?id=" + id;
		}else if(type == 2){
			window.location.href = "../Pointexchange/jfdhDetail.html?id=" + id;
		}
		
	});
	// 点击立即购买跳转购买界面
	$('body').on("click", ".fast_buy", function(event) {
		event.stopPropagation(); //阻止事件冒泡
		/*$.ajax({
		 url:'',
		 type:'get',
		 cache:false,
		 dataType:'json',
		 success:function(res) {
		 var data = JSON.pase(res);
		 if(data.code =="1"){
		 window.location.href = '';
		 }else{
		 console.log(data.msg);
		 }
		 },
		 error : function(err) {
		 console.log(err);
		 }
		 });//ajax结束*/
	}); //点击事件结束
});